#include<bits/stdc++.h>
using namespace std;
inline int max(int a,int b){
    return a>b?a:b;
}inline int min(int a,int b){
    return a<b?a:b;
}int n,a[200007],ans;
bool vis[2007];
void dfs(int x){
    if(x>n){
        int p=0;
        for(int i=1;i<=n;++i){
            for(int j=i-1;j;--j){
                if(vis[j]==vis[i]){
                    if(a[i]==a[j])p+=a[i];
                    break;
                }
            }
        }ans=max(ans,p);
        return;
    }vis[x]=1;
    dfs(x+1);
    vis[x]=0;
    dfs(x+1);
};

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T;cin>>T;while(T--){
        ans=0;
        cin>>n;
        for(int i=1;i<=n;++i)cin>>a[i];
        dfs(1);
        cout<<ans<<endl;
    }
    return 0;
}
